/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.lidovky.articles.articlesData.pesta;

import cz.mzk.lidovky.articles.domain.Genre;

/**
 *
 * @author x211800
 */
public class ColumnOfGenre extends Columns {

    private static final String CULTURE = "I";
    private static final String EDUCATIONCS = "I.1.4";
    private static final String EDUCATION = "I.2.4";
    private static final String LINGUISTICS = "II";
    private static final String LITERATURE = "III";
    private static final String ART = "IV";
    private Genre parsedGenre;
    private static ColumnOfGenre instance = null;

    private ColumnOfGenre() {
    }

    public static ColumnOfGenre instanceOf(String columnContent) throws ColumnsError{
        if (instance == null){
            instance = new ColumnOfGenre();
        }
        instance.parseColumn(columnContent);
        return instance;
    }


    /**
     *
     * @param column[0]
     * @return Genre{unparsed genres}
     * @throws ColumnsError{if genre is null}
     */
    public void parseColumn(String column) throws ColumnsError {
        parsedGenre = null;
        parsedGenre = parseGenre(removeTextDelimits(column));
        if (parsedGenre == null) {
            throw new ColumnsError("problem with genre");
        }
    }

    private Genre parseGenre(String gen) {

        String genreVolume = gen;
        Genre genre = null;
        if (genreVolume == null) {
            genre = Genre.CULTURE;
        } else if (genreVolume.startsWith(ART)) {
            genre = Genre.valueOfArt(genreVolume);
        } else if (genreVolume.startsWith(LITERATURE)) {
            genre = Genre.valueOfLiterature(genreVolume);
        } else if (genreVolume.startsWith(LINGUISTICS)) {
            genre = Genre.valueOfLinguistics(genreVolume);
        } else if (genreVolume.startsWith(EDUCATION) || genreVolume.startsWith(EDUCATIONCS)) {
            genre = Genre.valueOfEducation(genreVolume);
        } else if (genreVolume.startsWith(CULTURE)) {
            genre = Genre.valueOfCulture(genreVolume);
        } else {
            return null;
        }
        return genre;
    }

    public Genre getParsedGenre() {
        return parsedGenre;
    }

    
}
